$(function() {
	$('.VivaTimeline').vivaTimeline({
		carousel: true,
		carouselTime: 3000
	});
	
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});


function save() {
	var comment = $('#signupForm').serialize();
	$.ajax({
		cache : true,
		type : "POST",
		url : "/sales/order/saveReply",
		data : comment,
		async : false,
		error : function(request) {
			alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				parent.layer.msg(data.msg);
			}
		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i>";
	$("#signupForm").validate({
		rules : {
			remark : {
				required : true
			}
		},
		messages : {
			remark : {
				required : icon + "回复内容不能为空"
			}
		}
	});
}

/**
 * 图片批量上传
 */
function batchUploadImg(domId) {
	layer.open({
		id: 'img_batch_upload',
		type: 2,
		title: '批量上传',
		maxmin: true,
		shadeClose: false,
		area: ['60%', '80%'],
		content: '/platform/config' + '/batchUploadImg/'+ domId
	});
}

/**
 * 当页面上只有一个批量上传的入口时  domId可以忽略，多个时用以区分回调数据
 * @param domId
 * @param result
 */
function loadImgsInfo(domId, result) {
	if (!result || result.length <1) {
		parent.layer.msg("上传图片失败!",{icon:7});
		return;
	}
	$('#pic').val(result.join(","));
}

/**
 * 客服关闭工单
 */
function closeWorkOrder() {
	var workId = $('#workId').val();
	if (!workId) {
		parent.layer.msg("工单信息获取失败!",{icon:7});
		return;
	}
	layer.open({
		id: 'close_work',
		type: 2,
		title: '关闭工单',
		maxmin: true,
		shadeClose: false,
		area: ['60%', '80%'],
		content: '/sales/order/closeWorkOrder/'+ workId
	});
}

/**
 * 转财务处理页面
 */
function forwardCaiWu() {
	var workId = $('#workId').val();
	if (!workId) {
		parent.layer.msg("工单信息获取失败!",{icon:7});
		return;
	}
	layer.open({
		id: 'forward_cw',
		type: 2,
		title: '转财务处理',
		maxmin: true,
		shadeClose: false,
		area: ['80%', '90%'],
		content: '/sales/order/forwardCw/'+ workId
	});
}